#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <math.h>

// out = in^ (1./gamma_value)  in = i/255.f
void generate_gamma_lut(uint8_t *lut,float gamma_value)
{

    for (int i = 0;i < 256;i++)
    {
        float in = float(i) / 255.f;
        lut[i] = (uint8_t)(pow(in,1.f/gamma_value)*255.f);
    }
}


void gamma_correction(uint8_t *source,int width,int height,uint8_t *lutPtr)
{
    for (int i = 0;i < height;i++)
    {
        for (int j = 0;j < width;j++)
        {
            source[i*width+j] = lutPtr[source[i*width+j]];
        }
    }
}